<?php
header('Content-Type: charset=euc-kr');

$morningstar = 6;
$morningend = 9;

$nightstart = 21;
$nightend = 30;

$lunchstart = array('12', '20');
$lunchend = array('13', '20');

$start = 7;
$end = 12;


$starttime = mktime($start, 0, 0, date(m), date(d), date(y));
$endtime = mktime($end, 0, 0, date(m), date(d), date(y));
$totaltime = $endtime - $starttime;

$lunchstarttime = mktime($lunchstart['0'], $lunchstart['1'], 0, date(m), date(d), date(y));
$lunchendtime = mktime($lunchend['0'], $lunchend['1'], 0, date(m), date(d), date(y));
$lunchtime = $lunchendtime - $lunchstarttime;

if($starttime < $lunchstarttime && $endtime > $lunchendtime)
{
	$realtime = ($totaltime - $lunchtime) / 3600;
} else {
	$realtime = $totaltime / 3600;
}


$etctime = 0;
if($realtime > 8)
{
	$etctime = $realtime - 8;
}

$morningtime = 0;
if($start < $morningend)
{
	$morningtemp = $morningend - $start;;
	
	if($morningtemp > 3)
	{
		$morningtime = 3;
	} else {
		$morningtime = $morningend - $start;
	}
	
	if($etctime > 0)
	{
		$etctime = $etctime - $morningtime;
	}
}

$nighttime = 0;
if($end > $nightstart)
{
	if($start > $nightstart) {
		$nighttime = $end - $start;
	} else {
		$nighttime = $end - $nightstart;
	}
	
	if($end > $nightend)
	{
		$temp = $end - $nightend;
		$nighttime = $nighttime - $temp;
		
		if($temp > 3)
		{
			$morningtime = 3;
		} else 
		{
			$morningtime = $morningtime + $temp;
		}
	}
}


echo '총시간 = ' . number_format($totaltime / 3600, 1) . "\n";
echo '실제시간 = ' . number_format($realtime, 1) . "\n";
if($realtime > 7) {
	echo '기본 = 8.0' . "\n";
} else {
	echo '기본 = ' . number_format($realtime, 1) . "\n";
}

echo '잔여 = ' . number_format($etctime, 1) . "\n";
echo '아침 = ' . number_format($morningtime, 1) . "\n";
echo '야간 = ' . number_format($nighttime, 1) . "\n";

?>